/*------------------------------------------------------------------------------
 * Copyright 2012 NCR Corporation
 *------------------------------------------------------------------------------
 * All revision information is updated automatically from source code control
 * change records - please do not manually edit.
 *------------------------------------------------------------------------------
 *
 *  $LastChangedRevision:: 1588                                     $
 *  $LastChangedBy:: rb250096                                       $
 *  $LastChangedDate:: 2012-02-22 08:20:46 -0500 (Wed, 22 Feb 2012) $
 */

package com.ncr.nep.dashboardcore.modularization.client;

import java.util.HashMap;

/**
 * Provides an application-wide mechanism for storing and retrieving
 * {@link SplitPoint} objects by a unique ID or by class.
 *
 * @author rb250096
 * @version $Revision: 1588 $
 */
public class SplitPointRegistry {

    /**
     * The singleton instance.
     */
    protected static SplitPointRegistry instance = new SplitPointRegistry();

    /**
     * Map of unique IDs to {@link SplitPoint} objects.
     */
    protected HashMap<String, SplitPoint> pointsMap =
            new HashMap<String, SplitPoint>();

    /**
     * Constructor
     */
    protected SplitPointRegistry() { }

    /**
     * Registers 1 or more {@link SplitPoint} objects with the registry.
     *
     * @param splitPoints 1 or more {@link SplitPoint} objects.
     *
     * @throws IllegalArgumentException Thrown if another SplitPoint has
     * already been registered with the same registryId.
     */
    public static void register(SplitPoint ...splitPoints) {
        for(SplitPoint point : splitPoints) {
            if(!instance.pointsMap.containsKey(point.getRegistryId())) {
                instance.pointsMap.put(point.getRegistryId(), point);
            }
            else {
                throw new IllegalArgumentException("The registry ID " +
                         point.getRegistryId() +
                         " conflicts with an existing SplitPoint.");
            }
        }
    }

    /**
     * Gets the {@link SplitPoint} associated with the specified ID.
     *
     * @param id The ID of the SplitPoint to retrieve.
     *
     * @return The SplitPoint object, or null if none exists with the specified
     * ID.
     */
    public static SplitPoint get(String id) {
        return instance.pointsMap.get(id);
    }
}
